package wli.hibernate.db;

import static org.junit.Assert.*;

import java.util.Enumeration;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import wli.hibernate.util.HibernateUtil;
import wli.java.file.util.TextFileReader;

public class VocabularyTest {

	@Test
	public void test() {
		TextFileReader tfr = new TextFileReader();
		tfr.setFilename("c:\\apache\\htdocs\\SPELLING_BEE\\words-01.txt");
		tfr.getContent();
		Enumeration<String> enums = tfr.getWordList().elements();
		String temp = null;
		Vocabulary vc = null;
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
	
		while (enums.hasMoreElements()) {
			vc = new Vocabulary();
			temp = enums.nextElement();
			vc.setWord(temp);
			System.out.println(">>>>>>>>>>>>>>>" + temp);
			
			 try { transaction = session.beginTransaction();
			 System.out.println(">>>>>>>>>>>>>>>>>> [" + session.save(vc) +"] Saved.");
			
			transaction.commit(); 
			} 
			 catch (HibernateException e) {
			  transaction.rollback(); e.printStackTrace(); 
			  } 
		}
		
		session.close();
	}

}
